package com.hospital.workstation.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.Console;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.hospital.common.annotation.Log;
import com.hospital.common.annotation.RepeatSubmit;
import com.hospital.common.core.controller.BaseController;
import com.hospital.common.core.domain.PageQuery;
import com.hospital.common.core.domain.R;
import com.hospital.common.core.page.TableDataInfo;
import com.hospital.common.core.validate.AddGroup;
import com.hospital.common.enums.BusinessType;
import com.hospital.workstation.domain.bo.ElectronicManagerInfoBo;
import com.hospital.workstation.domain.vo.ElectronicManagerInfoVo;
import com.hospital.workstation.domain.vo.ElectronicMonitorOneInfoVo;
import com.hospital.workstation.domain.vo.ElectronicMonitorTwoInfoVo;
import com.hospital.workstation.service.IElectronicManagerInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * 电子监测管理信息
 *
 * @author whb
 * @date 2024-04-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/workstation/managerInfo")
public class ElectronicManagerInfoController extends BaseController {

    private final IElectronicManagerInfoService iElectronicManagerInfoService;

    /**
     * 查询管理信息详细信息（A表）
     *
     * @param id 主键
     */
    //@SaCheckPermission("workstation:managerInfo:query")
    @GetMapping("/{id}")
    public R<ElectronicMonitorOneInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                                 @PathVariable Long id) {
        return R.ok(iElectronicManagerInfoService.queryById(id));
    }

    /**
     * 查询管理信息详细信息（B表）
     *
     * @param id 主键
     * @return
     */
    //@SaCheckPermission("workstation:managerInfo:b:query")
    @GetMapping("/b/{id}")
    public R<ElectronicMonitorTwoInfoVo> getMonitorTwoInfo(@NotNull(message = "主键不能为空")
                                                           @PathVariable Long id) {
        return R.ok(iElectronicManagerInfoService.queryMonitorTwoInfoById(id));
    }

    /**
     * 查询电子监测管理信息列表
     */
    //@SaCheckPermission("workstation:managerInfo:list")
    @GetMapping("/list")
    public TableDataInfo<ElectronicManagerInfoVo> list(ElectronicManagerInfoBo bo, PageQuery pageQuery) {
        return iElectronicManagerInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 新增电子监测管理信息
     */
    //@SaCheckPermission("workstation:managerInfo:add")
    @Log(title = "电子监测管理信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ElectronicManagerInfoBo bo) {
        return iElectronicManagerInfoService.insertByBo(bo);
    }

    /**
     * 删除电子监测管理信息
     *
     * @param ids 主键串
     */
    //@SaCheckPermission("workstation:managerInfo:remove")
    @Log(title = "电子监测管理信息", businessType = BusinessType.DELETE)
    //@DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iElectronicManagerInfoService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 删除（A表）
     *
     * @param id 主键id
     * @return
     */
    //@SaCheckPermission("workstation:managerInfo:delete")
    @Log(title = "电子监测管理信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public R<Void> delete(@NotNull(message = "主键不能为空")
                          @PathVariable Long id) {
        return iElectronicManagerInfoService.deleteById(id);
    }

    /**
     * 删除（B表）
     *
     * @param id 主键id
     * @return
     */
    //@SaCheckPermission("workstation:managerInfo:b:delete")
    @Log(title = "电子监测管理信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/b/{id}")
    public R<Void> delete2(@NotNull(message = "主键不能为空")
                           @PathVariable Long id) {
        return iElectronicManagerInfoService.deleteById2(id);
    }

    /**
     * 导出json
     *
     * @param response
     * @param ids      A表id集合
     */
    @GetMapping("/json/{ids}")
    public void exportJson(HttpServletResponse response, @PathVariable Long[] ids) throws IOException {
        iElectronicManagerInfoService.exportJson(response, ids);
    }
}
